//
//  BHFunDetailInfoModel.swift
//  BigHealth
//
//  Created by 蔺百好 on 2021/8/10.
//

import UIKit

class BHFunDetailInfoModel: NSObject {
    var funId: String = ""
    var name: String = ""
    var cityName: String = ""
    var areaName: String = ""
    var distance: String = "" // 距离; 用户未授权  为null
    var beginTime: String = ""
    var venueName: String = "" // 场馆名称/自定义地址
    var venueId: String = ""
    var longitude: String = ""
    var latitude: String = ""
    var price: String = ""
    var typeOneLabel: String = "" // 一级运动类型label
    var typeTwoLabel: String = "" // 二级运动类型label
    
    var remarks: String = "" // 分类补充
    var signupEndTime: String = "" // 报名结束时间
    var cover: String = "" // 场馆封面   自定义地址没有
    var launchUserId: String = "" // 发起人id
    var launchUserName: String = "" // 发起人姓名
    var launchAvatar: String = "" // 发起人头像
    var introduce: String = "" // 介绍
    var contactNumber: String = "" //联系电话
    var groupId: String = "" // 群聊id
    
    var urlList: [BHImageOrVideoModel] = [] // 图片
    
  

    var limitPerson: Int = 0 // 限制人数
    var surplusPerson: Int = 0 //  剩余名额
    var signStatus: Int = 0 // 报名按钮状态  1:立即报名  2:已报名  3.人数已满
    var collectionFlag: Int = 0 // 收藏  0:否 1:是
    var signPerson: Int = 0 //报名人数

    
    
    func parseDic(_ dic: [String:Any]) {
        self.venueName = BHJsonTool.decodeStringFromDic(dic: dic, key: "venueName")
        self.cityName = BHJsonTool.decodeStringFromDic(dic: dic, key: "cityName")
        self.distance = BHJsonTool.decodeStringFromDic(dic: dic, key: "distance")
        self.areaName = BHJsonTool.decodeStringFromDic(dic: dic, key: "areaName")
        self.typeOneLabel = BHJsonTool.decodeStringFromDic(dic: dic, key: "typeOneLabel")
        self.typeTwoLabel = BHJsonTool.decodeStringFromDic(dic: dic, key: "typeTwoLabel")
        self.price = BHJsonTool.decodeStringFromDic(dic: dic, key: "price")
        self.name = BHJsonTool.decodeStringFromDic(dic: dic, key: "name")
        self.funId = BHJsonTool.decodeStringFromDic(dic: dic, key: "id")
        self.beginTime = BHJsonTool.decodeStringFromDic(dic: dic, key: "beginTime")
        self.venueId = BHJsonTool.decodeStringFromDic(dic: dic, key: "venueId")

        self.remarks = BHJsonTool.decodeStringFromDic(dic: dic, key: "remarks")
        self.signupEndTime = BHJsonTool.decodeStringFromDic(dic: dic, key: "signupEndTime")
        self.cover = BHJsonTool.decodeStringFromDic(dic: dic, key: "cover")
        self.launchUserId = BHJsonTool.decodeStringFromDic(dic: dic, key: "launchUserId")
        self.launchUserName = BHJsonTool.decodeStringFromDic(dic: dic, key: "launchUserName")
        self.launchAvatar = BHJsonTool.decodeStringFromDic(dic: dic, key: "launchAvatar")
        self.introduce = BHJsonTool.decodeStringFromDic(dic: dic, key: "introduce")
        self.contactNumber = BHJsonTool.decodeStringFromDic(dic: dic, key: "contactNumber")
        self.groupId = BHJsonTool.decodeStringFromDic(dic: dic, key: "groupId")

        self.limitPerson = BHJsonTool.decodeIntFromDic(dic: dic, key: "limitPerson")
        self.surplusPerson = BHJsonTool.decodeIntFromDic(dic: dic, key: "surplusPerson")
        self.signStatus = BHJsonTool.decodeIntFromDic(dic: dic, key: "signStatus")
        self.collectionFlag = BHJsonTool.decodeIntFromDic(dic: dic, key: "collectionFlag")
        self.signPerson = BHJsonTool.decodeIntFromDic(dic: dic, key: "signPerson")

        let array = BHJsonTool.decodeArrayFromDic(dic: dic, key: "urlList")
        if self.urlList.count != 0 {
            self.urlList.removeAll()
        }
        
        for item in array {
            if item is NSNull {
                
            }else {
                let model = BHImageOrVideoModel.init()
                model.imageUrl = item as? String
                self.urlList.append(model)
            }
        }
        
    }
    
    lazy var imageRows: Int = {
        if self.urlList.count == 0 {
            return 0
        }else {
            let row = self.urlList.count/3
            let last = self.urlList.count%3
            if last != 0 {
                return row+1
            }else {
                return row
            }
        }
    }()
    
    
    lazy var introduceHeight: CGFloat = {
        if self.introduce.isEmpty == true {
            return 0
        }else {
            let height_ = self.introduce.calSizeOfText(font: .systemFont(ofSize: 14, weight: .medium), size: CGSize(width: UIScreen.width-40, height: CGFloat.greatestFiniteMagnitude)).height
            
            return ceil(height_)
        }
    }()
    
}
